from middlewared.service import Service


class UsageService(Service):

    FAILED_RETRIES = 3

    class Config:
        private = True

    async def firstboot(self):
        _hash = await self.middleware.call('system.host_id')
        version = await self.middleware.call('system.version')
        retries = self.FAILED_RETRIES
        # print("------------firstboot-------------")
        # 第一次安装hccnas系统启动时同步推送应用信息
        # print("-----1---firstboot-------")
        data_dict = {"type": "start","data": {"uuid": "", "ip": "", "app_id": "","app_name": ""}}
        await self.middleware.call('catalog.hccnas_push', str(data_dict))
        # print("-----2---firstboot-------")
        # 屏蔽在每次重启时推送日志
        # while retries:
        #     try:
        #
        #         await self.middleware.call('usage.submit_stats', {
        #             'platform': 'TrueNAS-SCALE',
        #             'system_hash': _hash,
        #             'firstboot': [{'version': version}]
        #         })
        #     except Exception:
        #         retries -= 1
        #         if not retries:
        #             self.logger.error('Failed to send firstboot statistics', exc_info=True)
        #     else:
        #         break

